home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Ahoy 1986 July
/
Ahoy_Magazine_86-07_1986_Double_L.d64
/
sort 64
(
.txt
)
< prev
next >
Wrap
Commodore BASIC
|
2022-10-26
|
707b
|
43 lines
1 print"[147]":poke53280,5:poke53281,0:poke646,7
2 rem > insertion sort 64 <
3 rem rupert report #31
4 rem =-=- basic 2.0 -=-=
10 m$="this is a test message"
15 n=len(m$)
20 dim a$(n) : a$(0)=""
30 rem - input the array
40 gosub 220
50 rem - sort the array
60 gosub 110
70 rem - print the sorted array
80 gosub 300
90 end
100 :
110 rem == insertion sort ==
120 :
130 for i=2 to n
140 v$=a$(i) : j=i
150 if a$(j-1)<=v$ then 180
160 a$(j)=a$(j-1) : j=j-1
170 goto 150
180 a$(j)=v$
190 next i
200 return
210 :
220 rem == input array ==
230 :
240 for k=1 to n
250 a$(k)=mid$(m$,k,1)
260 print a$(k);
270 next k
280 return
290 :
300 rem == print array ==
310 :
320 print:print"sorted:"
330 for k=1 to n
340 print a$(k);
350 next k
355 print:print"list this program for details"
360 return